<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/ajax.js"></script>
</head>

<body>
    <button>获取xml格式的数据</button>
    <script>
        const btnObj = document.querySelector("button");
        btnObj.onclick = function () {
            ajax({
                url: 'http://120.78.190.136:8088/spboot/xmlFormat',
                success: function (data, xmlHttpReqeust) {
                    /* 
                    <students>
                        
                        <student>
                            <sid>001</sid>
                            <name>张三</name>
                        </student>

                        <student>
                            <sid>002</sid>
                            <name>王二丫</name>
                        </student>
                    </students>
                    
                    */
                    /* 
                     data：返回的是字符串，不方便解析。
                    
                    */
                    console.log(data);
                    // 返回的是文档对象
                    console.log(xmlHttpReqeust.responseXML);
                    const xmlObj = xmlHttpReqeust.responseXML;
                    const stu1 = xmlObj.querySelector("student");
                    console.log(stu1.querySelector("name").nodeValue);
                    console.log(stu1.querySelector("name").innerHTML);
                    /* 
                        总结：操作xml标签，就跟操作html标签是一模一样的。
                    */
                }
            });
        }
    </script>
</body>

</html>